<template>
    <div class="mod-order" style="margin: 10px">
        <!--查询面板-->
        <SearchPanel ref="searchPanel" :selectOptions="selectOptions" :search-config="searchConfig" @startSearch="startSearch">
        </SearchPanel>

        <!-- 查询结果 -->
        <ResultListPanel
            tableRef="table"
            ref="multipleTable"
            :checkBoxEnable="true"
            :data="dataList ? dataList : []"
            :listConfig="resultColConfig"
            :listLoading="listLoading"
            @actionClick="actionClick"
            @paginationChange="paginationChange"
            :tagTextExchange="tagTextExchange"
            @selectionChange="selectionChange"
            :actionLimit="actionLimit"
            :actionLimitName="actionLimitName"
        ></ResultListPanel>
    </div>
</template>

<script>
import { INDEX_SEARCH_CONFIG, INDEX_SEARCH_RESULT_ITEMS, INDEX_SEARCH_SELECT_OPTIONS_CONFIG } from './config';
import ResultListPanel from '../../components/ResultListPanel';
import SearchPanel from '../../components/SearchPanel';
import API from '@/api';
import cloneDeep from 'lodash/cloneDeep';

export default {
    components: {
        ResultListPanel,
        SearchPanel
    },
    data() {
        var appidValdate = (rule, value, callback) => {
            var regex = /^[0-9a-zA-Z]{3,8}$/g;
            if (!regex.test(value)) {
                callback(new Error('请输入正确的appid'));
            } else {
                callback();
            }
        };

        return {
            visible: false,
            selectDataList: [],
            // 搜索项配置
            searchConfig: INDEX_SEARCH_CONFIG,
            resultColConfig: INDEX_SEARCH_RESULT_ITEMS,
            listLoading: false, // 数据列表显示状态
            dataList: [], //  数据列表
            /* 分页查询数据 */
            pageSize: 10,
            pageNum: 1,
            totalPage: 0,
            qFlag:'',
            /* 查询条件参数 */
            dataForm: {
                keyword: null,
                checkStatus: '0'
            },
            type: 1,
            selectOptions: INDEX_SEARCH_SELECT_OPTIONS_CONFIG
        };
    },

    mounted() {
        this.getList();
    },

    watch: {
        //- 解决 同一页面，数据不刷新问题

        // 监听相同路由下参数变化的时候，从而实现异步刷新
        $route(to, from) {
            this.getList();
            this.nickname = this.$route.query.nickname; //修改页面标题
        }
    },

    methods: {
        selectionChange(val) {
            console.log(val);
            this.selectDataList = val;
        },

        /***
         * 搜索面板触发 搜索事件
         * @param params
         */
        startSearch(params) {
            this.dataForm = params;
            this.pageNum = 1;
            this.$set(this.$refs.multipleTable['pageParams'], 'pageNum', 1);

            this.getList();
        },

        /***
         * 触发 列表 操作按钮 （ 编辑 和 删除 ）
         * @param data
         * @param item
         */
        actionClick([data, item]) {
            if (item.alias === 'audit') {
                data.opFlag=this.qFlag;
                switch (this.$route.path) {
                    case '/publicProcessApproval/jdshgl/index':
                        //基地商户管理  审批详情
                        this.$router.push({ path: '/publicProcessApproval/jdshgl/auditDetails', query: { itemData: data} });

                        break;
                    case '/publicProcessApproval/fkgl/index':
                        //风控管理 审批详情
                        this.$router.push({ path: '/publicProcessApproval/fkgl/auditDetails', query: { itemData: data } });
                        break;

                    case '/publicProcessApproval/zjgl/index':
                        //资金管理 审批详情
                        this.$router.push({ path: '/publicProcessApproval/zjgl/auditDetails', query: { itemData: data} });

                        break;
                }
            }
        },

        tagTextExchange(item) {},
        actionLimit([data, obj]) {

            //操作 按钮显示隐藏  
            // if (this.dataForm.checkStatus == '0') { //未审核，才能操作
            //     if (obj.alias == 'audit' && data.flowStatusEnumStr == '审核通过(完成)') {
            //         return false;
            //     } else {
            //         return true;
            //     }
            // } else { //已审核，都不能操作
            //     return false;
            // }

            return true;
        },

        actionLimitName([data, action]){

             if (this.qFlag== '0') { //未审核，才能操作

                if (action.alias == 'audit' && data.flowStatusEnumStr == '审核通过(完成)') {
                    return "详情";
                } else {
                    return action.name;
                }

            } else { //已审核，看详情
                  
                 return "详情";
               
            }

        },

        /**
         * 分页器发生改变 触发事件
         * @param page
         */
        paginationChange(page) {
            this.pageSize = page.pageSize;
            this.pageNum = page.pageNo;
            this.getList();
        },

        // 列表 接口
        getList() {
            this.qFlag=this.dataForm.checkStatus;
            let params = cloneDeep(this.dataForm);
            params.pageNum = this.pageNum;
            params.pageSize = this.pageSize;

            this.listLoading = true;

            API.publicProcessApproval.getList(params).then((res) => {
                console.log(res);

                this.listLoading = false;
                this.totalPage = res.result.total;
                this.dataList = res.result.rows;

                this.$set(this.$refs.multipleTable['pageParams'], 'total', res.result.total);
            });
        }
    }
};
</script>

<style>
</style>